package com.sugon.controller.device;

import com.sugon.entity.AlarmCategoryEntity;
import com.sugon.service.AlarmCategoryService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 报警分类表Controller
 *
 * @author sugon
 * @date 2023-03-13 14:49:19
 */
@Controller
@RequestMapping("alarmcategory")
public class AlarmCategoryController {
    @Autowired
    private AlarmCategoryService alarmCategoryService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<AlarmCategoryEntity> alarmCategoryList = alarmCategoryService.queryList(query);
        int total = alarmCategoryService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(alarmCategoryList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @ResponseBody
    public R info(@PathVariable("id") String id) {
        AlarmCategoryEntity alarmCategory = alarmCategoryService.queryObject(id);

        return R.ok().put("alarmCategory", alarmCategory);
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<AlarmCategoryEntity> list = alarmCategoryService.queryList(params);

        return R.ok().put("list", list);
    }
}
